/*
* Copyright 2016 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-wechat-open-api
*
* @File name : MaintainRecordController.java
*
* @Author : Administrator
*
* @Date : 2016年12月1日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2016年12月1日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmcc.gateway.wechat.controller.customerinfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.marketing.common.dto.customerInfo.MaintainRecordDto;
import org.marketing.common.util.CheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.gmcc.gateway.wechat.common.ApiVersionConsts;
import com.yonyou.gmcc.gateway.wechat.service.interfaces.MaintainRecordServiceInterface;

/**
*
* @author QianKun
* 保养记录API-接口
* @date 2016年12月1日
*/
@RestController
@RequestMapping(value = ApiVersionConsts.BASE_PATH+"/potentialUsers/maintainRecord" )
public class MaintainRecordController {

    @Autowired
    private MaintainRecordServiceInterface maintainRecordServiceInterface;
    
    
    /**
    *
    * @author QianKun
    * 添加保养记录
    * @date 2016年12月1日
    * @param maintainRecordDto
    * @return
    * @throws Exception
    */
    @RequestMapping(method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public @ResponseBody Map<String, Object> saveMaintainRecord(@RequestBody MaintainRecordDto maintainRecordDto) throws Exception {

        Map<String, Object> resultMap = maintainRecordServiceInterface.saveMaintainRecord(maintainRecordDto);
        return resultMap;
    }
    
    
    /**
    *
    * @author QianKun
    * 查询上次保养记录
    * @date 2016年12月1日
    * @param userId
    * @param carId
    * @return
    */
    @RequestMapping(value = "/lastMaintain", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<MaintainRecordDto> getLastMaintainData(@RequestParam("userId") String userId,@RequestParam("vin") String vin) {
        List<MaintainRecordDto> dtoList = maintainRecordServiceInterface.getLastMaintainData(userId,vin);
        if (CheckUtil.NullOrEmpty(dtoList)) {
            dtoList = new ArrayList<>();
        }
        return dtoList;
    }
    
}
